<template>
    <div class="user-table-list">
        <el-table
                ref="userTable"
                :data="tableData"
                :height="tableHeight"
                border
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange"
                :default-sort="defaultSort">
            <el-table-column
                    type="selection"
                    show-overflow-tooltip
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="number"
                    label="编号"
                    width="95"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="userName"
                    label="用户名"
                    width="200"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="adminCategory"
                    label="管理员分类"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="employeeName"
                    label="员工姓名"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="departmentName"
                    label="部门名称"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="createDate"
                    label="创建日期"
                    width="125"
                    sortable>
            </el-table-column>
            <el-table-column
                    prop="authorizedStatus"
                    label="授权状态"
                    width="125"
                    :filters="authorizedStatusFilter"
                    :filter-method="filterAuthorizedStatus"
                    filter-placement="bottom-end">
                <template slot-scope="scope">
                    <el-tag :type="scope.row.authorizedStatus === '启用' ? 'success' : 'danger'" close-transition>
                        {{scope.row.authorizedStatus}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            @click="handleEdit(scope.$index, scope.row)">编辑
                    </el-button>
                    <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除
                    </el-button>
                    <el-button size="mini" type="primary" @click="handleLook(scope.$index, scope.row)">查看</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    export default {
        name: "UserTableList",
        props: {
            tableHeight: {
                required: false,
                type: String,
                default: () => {
                    return "550";
                }
            },
            defaultSort: {
                required: false,
                type: Object,
                default: () => {
                    return {prop: 'number', order: 'descending'};
                }
            }
        },
        computed: {
            authorizedStatusFilter() {
                return [{text: '启用', value: '启用'}, {text: '禁用', value: '禁用'}]
            }
        },
        data() {
            return {
                multipleSelection: [],
                tableData: [{
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '禁用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }, {
                    number: '10021',
                    userName: 'wangxiaohu',
                    adminCategory: '系统管理员',
                    employeeName: '王文敏',
                    departmentName: '研发部',
                    createDate: '2016-05-03',
                    authorizedStatus: '启用',
                }],
            }
        },
        methods: {
            /**
             * 编辑
             * @param index
             * @param row
             */
            handleEdit(index, row) {
                console.log(index, row);
                this.$parent.$parent.curPath = `edit@${row.number}`;
            },
            /**
             * 删除
             * @param index
             * @param row
             */
            handleDelete(index, row) {
                console.log(index, row);
            },
            /**
             * 查看
             * @param index
             * @param row
             */
            handleLook(index, row) {
                console.log(index, row);
                this.$parent.$parent.curPath = `look@${row.number}`;
            },
            /**
             * 授权状态过滤
             * @param value
             * @param row
             * @returns {boolean}
             */
            filterAuthorizedStatus(value, row) {
                return row.authorizedStatus === value;
            },
            /**
             * 行背景色处理
             * @param row
             * @param rowIndex
             * @returns {string}
             */
            tableRowClassName({row, rowIndex}) {
                if (row.authorizedStatus === '禁用') {
                    return 'danger-row';
                } else if (row.authorizedStatus === '启用') {
                    return 'success-row';
                }
                return '';
            },
            /**
             * 选中行处理
             * @param val
             */
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style lang="scss">
    .user-table-list {

    }
</style>